package com.example.hp.myapplication.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.example.hp.myapplication.R;
import com.example.hp.myapplication.activity.GuideActivity;
import com.example.hp.myapplication.activity.MainActivity;
import com.example.hp.myapplication.activity.MainActivity2;

import java.util.List;

/**
 * Created by hp on 2018/5/29.
 */

public class MyPadgerAdapet extends PagerAdapter {
    private List<View> viewList;
    private Context ctx;

    public MyPadgerAdapet(List<View> viewList, Context ctx) {
        this.viewList = viewList;
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return viewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
       return  view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(viewList.get(position));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view=viewList.get(position);
        if (position!=viewList.size()-1)
        {
            view.findViewById(R.id.btnLogin).setVisibility(View.GONE);
        }
        else
        {
            view.findViewById(R.id.btnLogin).setVisibility(View.VISIBLE);
            view.findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent it=new Intent(ctx, MainActivity2.class);
                    ((GuideActivity)ctx).startActivity(it);
                    ((GuideActivity)ctx).finish();
                }
            });

        }
        view.findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent(ctx, MainActivity2.class);
                ((GuideActivity)ctx).startActivity(it);
                ((GuideActivity)ctx).finish();
            }
        });
        container.addView(view);
        return view;
    }

}
